package cn.gmph.blog.admin.service.sys.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gmph.blog.admin.service.sys.dao.helper.UsersProvider;
import cn.gmph.blog.admin.service.sys.entity.UsersDO;

import java.util.List;;

public interface UsersDAO {

    @Results({@Result( column = "ID",property = "id"),@Result( column = "user_login",property = "userLogin"),@Result( column = "user_pass",property = "userPass"),@Result( column = "user_nicename",property = "userNicename"),@Result( column = "user_email",property = "userEmail"),@Result( column = "user_url",property = "userUrl"),@Result( column = "user_registered",property = "userRegistered"),@Result( column = "user_activation_key",property = "userActivationKey"),@Result( column = "user_status",property = "userStatus"),@Result( column = "display_name",property = "displayName") })
    @Select("SELECT * FROM wp_users WHERE id = #{id}")
    public UsersDO getById(@Param("id") int id);

    @Insert("INSERT into wp_users(ID,user_login,user_pass,user_nicename,user_email,user_url,user_registered,user_activation_key,user_status,display_name) VALUES (#{id},#{userLogin},#{userPass},#{userNicename},#{userEmail},#{userUrl},#{userRegistered},#{userActivationKey},#{userStatus},#{displayName})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insert(UsersDO users);

    @Delete("DELETE FROM wp_users WHERE id = #{id}")
    public int deleteById(@Param("id") Long id);

    @UpdateProvider(type = UsersProvider.class, method = "update")
    public int update(@Param("users") UsersDO  users);

    @Results({@Result( column = "ID",property = "id"),@Result( column = "user_login",property = "userLogin"),@Result( column = "user_pass",property = "userPass"),@Result( column = "user_nicename",property = "userNicename"),@Result( column = "user_email",property = "userEmail"),@Result( column = "user_url",property = "userUrl"),@Result( column = "user_registered",property = "userRegistered"),@Result( column = "user_activation_key",property = "userActivationKey"),@Result( column = "user_status",property = "userStatus"),@Result( column = "display_name",property = "displayName") })
    @SelectProvider(type = UsersProvider.class, method = "pageList")
    public List<UsersDO> pageList(@Param("users") UsersDO users, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @SelectProvider(type = UsersProvider.class, method = "pageListCount")
    public Integer pageListCount(@Param("users") UsersDO users);

}